/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BE;

/**
 *
 * @author BentH
 */
public class Song
{

    private final int id;
    private String title;
    private int BMP;
    private int duration;
    private boolean favorite;
    private Artist artist;
    private Category category;

    public Song(int id, String title, Artist artist, Category category, int BMP, int duration, boolean favorite)
    {
        this.id = id;
        this.title = title;
        this.artist = artist;
        this.category = category;
        this.BMP = BMP;
        this.duration = duration;
        this.favorite = favorite;
    }

    public Song(String title, Artist artist, Category category, int BMP, int duration, boolean favorite)
    {
        this(-1, title, artist, category, BMP, duration, favorite);
    }

    public Song(int id, Song s)
    {
        this(id, s.getTitle(), s.getArtist(), s.getCategory(), s.getBMP(), s.getDuration(), s.isFavorite());
    }

    /**
     * @return the id
     */
    public int getId()
    {
        return id;
    }

    /**
     * @return the title
     */
    public String getTitle()
    {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title)
    {
        this.title = title;
    }

    /**
     * @return the BMP
     */
    public int getBMP()
    {
        return BMP;
    }

    /**
     * @param BMP the BMP to set
     */
    public void setBMP(int BMP)
    {
        this.BMP = BMP;
    }

    /**
     * @return the duration
     */
    public int getDuration()
    {
        return duration;
    }

    /**
     * @param duration the duration to set
     */
    public void setDuration(int duration)
    {
        this.duration = duration;
    }

    /**
     * @return the favorite
     */
    public boolean isFavorite()
    {
        return favorite;
    }

    /**
     * @param favorite the favorite to set
     */
    public void setFavorite(boolean favorite)
    {
        this.favorite = favorite;
    }

    /**
     * @return the artist
     */
    public Artist getArtist()
    {
        return artist;
    }

    /**
     * @param artist the artist to set
     */
    public void setArtist(Artist artist)
    {
        this.artist = artist;
    }

    /**
     * @return the category
     */
    public Category getCategory()
    {
        return category;
    }

    /**
     * @param category the category to set
     */
    public void setCategory(Category category)
    {
        this.category = category;
    }

    @Override
    public String toString()
    {
        int seconds = (duration + 500) / 1000;
        int minutes = duration / 60;
        seconds = duration % 60;
        return String.format("%4d %-30s %-30s %-20s %4d %02d:%02d %s", id, title, artist.getName(), category.getName(), BMP, minutes, seconds, isFavorite());
    }

    /**
     * Songs with the same id are considered equal.
     *
     * @param o the song to test equality for
     * @return true, if the song id's are equal.
     */
    @Override
    public boolean equals(Object o)
    {
        if (!(o instanceof Song))
        {
            return false;
        }
        Song s = (Song) o;
        return (this.getId() == s.getId());
    }

    @Override
    public int hashCode()
    {
        int hash = 3;
        hash = 37 * hash + this.id;
        return hash;
    }

}
